package lily.phs.healthedu;
import lily.phs.database.Constants;
import lily.phs.mental.MentalScrollLayout;
import lily.phs.mental.MentalerDetails;
import lily.phs.object.HealthEdu;
import lily.phs.urh.R;
import lily.phs.vaccination.VaccinationCardView;
import lily.ui.control.MyPopupWindow;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
public class Jkjy extends Activity implements OnClickListener,Constants 
{
	private static final String[] nameOfModuleList = {
    	"城乡居民健康档案管理","健康教育","疫情上报","卫生监督","寓教于乐"};
    private static final int[] imageOfModuleList = {
    	R.drawable.peoplehealth,R.drawable.health_education,R.drawable.yiqingshangbao,
    	R.drawable.weishengjiandu,R.drawable.entertain};
    private static final String[] vaccinationTable={"健康教育活动记录表"};
    private HealthEduView hev;
    HealtheduScrollLayout mRoot;

    private int pageIndex;
    
    
	private EditText etFillTime;
	private int profileID=0,father,call;
	private LinearLayout llContent;
	private MyPopupWindow mPopupWindow;
	ScrollView sv;
	private Button btnBack,btnAdd,btnSave,btnUpdate;
	private ProgressDialog mpDialog;
	
	private int profileid=0;
	
	public Handler mHandler = new Handler(){
    	@Override
    	public void handleMessage(Message msg) {
    		super.handleMessage(msg);
			int state = msg.what;
			if(state==1){
				pageIndex = mRoot.getCurScreen();
				switch(pageIndex){
				case 0:{
					btnAdd.setVisibility(View.GONE);
					break;
				}
				case 1:
				case 2:{
					btnAdd.setVisibility(View.VISIBLE);
					break;
				}
				}
			}
    	}
    };
    
	@Override	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		int state = getIntent().getExtras().getInt("state");
		if(state==1){//查看
			profileid = getIntent().getExtras().getInt("Profile_id");
			
		}
		else if(state==2){
			//添加
		   HealthEdu newEdu = new HealthEdu(this);
	       Cursor cursor = this.managedQuery(CONTENT_URI_TB25, null, null, null, null);
	       profileid = cursor.getCount()+1;
	       newEdu.insertHealthEdu();
		}
       
       
		hev = new HealthEduView(this,profileid);
		hev.findViewsById();
		hev.fetchData();
		hev.initViews();
		hev.setMyView();
		//setContentView(hev);
		
		
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(hev);
        //setContentView(R.layout.mentaler_details);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title_2);
        
        btnBack = (Button)this.findViewById(R.id.title_left_btn);
        btnBack.setText("后退");
        btnBack.setOnClickListener(this);
        btnAdd = (Button)this.findViewById(R.id.title_right_btn0);
        btnAdd.setText("新建");
        btnAdd.setOnClickListener(this);
        btnAdd.setVisibility(View.GONE);
        btnSave = (Button)this.findViewById(R.id.title_right_btn);
        btnSave.setText("保存");
        btnSave.setOnClickListener(this);
        btnUpdate = (Button)this.findViewById(R.id.title_right_btn2);
        btnUpdate.setText("提交");
        btnUpdate.setOnClickListener(this);
//        profileID = getIntent().getExtras().getInt("Profile_id");
        
        btnBack.setOnClickListener(new Button.OnClickListener()
        {
        	public void onClick(View v) 
        	{
        		// TODO Auto-generated method stub
        		if(v==btnBack)
        		{
        			new AlertDialog.Builder(Jkjy.this)
        			.setIcon(R.drawable.alert_dialog_icon)
        			.setTitle("您确定已经保存了要退出吗？")
        			.setPositiveButton("确定", new DialogInterface.OnClickListener(){
        				public void onClick(DialogInterface dialog, int whichButton) {
        					Intent intent = new Intent();
        					intent.setClass(Jkjy.this, Healthedu.class);
        					setResult(RESULT_OK, intent);
        					startActivity(intent);
        					finish();
        					overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
        				}
        			})
        			.setNegativeButton("取消", new DialogInterface.OnClickListener() {
        		                    public void onClick(DialogInterface dialog, int whichButton) {

        		                        /* User clicked Cancel so do some stuff */
        		                   }
        		                })
        		                .create().show();	
        			}
        		}
        });  
        btnSave.setOnClickListener(new Button.OnClickListener()
    	{
        	//pageIndex = mRoot.getCurScreen();
        	@Override
        	public void onClick(View v) {
        		// TODO Auto-generated method stub
        		if(v==btnSave){
        			hev.saveViews();
        			Toast.makeText(Jkjy.this, "信息保存成功!", Toast.LENGTH_SHORT).show();
        			}
        		}
        	
        		
        	
    	});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}	
}